using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.WowAddonStudio.Lua.RuntimeService.WowBench.Resolvers;

namespace Microsoft.WowAddonStudio.Lua.RuntimeService.ShellHost
{
	/// <summary>
	/// Represents a host application command with aguments and sub-commands.
	/// </summary>
	public sealed class ShellCommandSet
	{
		public static readonly ShellCommandSet Default = CommandSetLine;
		public static readonly ShellCommandSet LuaPrompt = new ShellCommandSet(@"lua.exe");
		public static readonly ShellCommandSet CommandSetLine = new ShellCommandSet(@"cmd.exe");
		public static readonly ShellCommandSet WoWBenchPrompt = new ShellCommandSet(@"lua.exe wowbench.lua -f -v");
		public static readonly ShellCommandSet WoWBenchPromptArgs = new ShellCommandSet(LuaPrompt.Host, null, @"wowbench.lua -f -v");
		public static readonly ShellCommandSet CmdWoWBenchPrompt = new ShellCommandSet(CommandSetLine.Host, new List<string> {WoWBenchPrompt.Host});
		public static readonly ShellCommandSet WoWBenchPromptWithAddon = new ShellCommandSet(LuaPrompt.Host, null, String.Concat("wowbench.lua -f -v ", CommandResolver.AddOnNameToken));
		public static readonly ShellCommandSet CmdWoWBenchPromptWithAddon = new ShellCommandSet(CommandSetLine.Host, new List<string>
		                                                                                        	{
		                                                                                        		String.Concat(WoWBenchPrompt.Host, CommandResolver.AddOnNameToken)
		                                                                                        	});

		/// <summary>
		/// Initializes a new instance of the <see cref="ShellCommandSet"/> class.
		/// </summary>
		/// <param name="host"></param>
		private ShellCommandSet(string host) : this(host, null)
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="ShellCommandSet"/> class.
		/// </summary>
		/// <param name="host"></param>
		/// <param name="commandSet"></param>
		private ShellCommandSet(string host, List<string> commandSet)
		{
			CommandSet = commandSet;
			Host = host;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="ShellCommandSet"/> class.
		/// </summary>
		/// <param name="host"></param>
		/// <param name="commandSet"></param>
		/// <param name="argument"></param>
		private ShellCommandSet(string host, List<string> commandSet, string argument)
		{
			CommandSet = commandSet;
			Host = host;
			Argument = argument;
		}

		/// <summary>
		/// Gets or sets the host.
		/// </summary>
		/// <value>The host.</value>
		public string Host { get; private set; }

		/// <summary>
		/// Gets or sets the command set.
		/// </summary>
		/// <value>The command set.</value>
		public List<string> CommandSet { get; private set; }

		/// <summary>
		/// Gets or sets the argument.
		/// </summary>
		/// <value>The argument.</value>
		public string Argument { get; private set; }

		/// <summary>
		/// Returns a <see cref="System.String"/> that 
		/// represents the current <see cref="ShellCommandSet"/>.
		/// </summary>
		/// <returns>The host with arguments and commands.</returns>
		public override string ToString()
		{
			var builder = new StringBuilder();
			builder.Append("Host:"); builder.Append(Host);
			builder.Append(" with arguments:"); builder.Append(Argument);
			if (CommandSet != null)
				CommandSet.ForEach(command =>
				                   	{
				                   		builder.AppendLine("Command:"); builder.Append(command);
				                   	});
			return builder.ToString();
		}
	}
}